package com.sharkpro.designPattern.myIO;

import cn.hutool.core.io.FileUtil;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author jianxin.wei
 * @description 原生输入输出流
 * @date 2024/12/18 10:26
 */
public class InputAndOutStream {

    private static final String FILENAME = "E:\\shark\\All\\sharkPro\\src\\main\\java\\com\\sharkpro\\designPattern\\myAdapter\\test.txt";

    public static void main(String[] args) throws IOException {
//        FileInputStream fis = new FileInputStream(FILENAME);
//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
//        byte[] buffer = new byte[2];
//        int bytesRead;
//        while ((bytesRead = fis.read(buffer)) != -1) {
//            baos.write(buffer, 0, bytesRead);
//        }
//
//        // 使用正确的字符编码将字节数组转换为字符串
//        String content = baos.toString("UTF-8"); // 或者 "GBK" 视文件编码而定
//        System.out.println(content);

        String read = FileUtil.readUtf8String(FILENAME);
        System.out.println(read);
        read = read.replace("我","你");
        FileUtil.writeUtf8String(read,FILENAME);

    }
}
